Use the same G_IO_ERROR_* values for HTTP status codes in both fetchers.
The libsoup fetcher still handles a few more internal error codes than
the libcurl one; this could be built on in future.
Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #1594
Approved by: jlebon
curl_easy_getinfo (easy, CURLINFO_RESPONSE_CODE, &response);
if (!is_file && !(response >= 200 && response < 300))
{
- GIOErrorEnum giocode;
-
- /* TODO - share with soup */
- switch (response)
- {
- case 404:
- case 403:
- case 410:
- giocode = G_IO_ERROR_NOT_FOUND;
- break;
- default:
- giocode = G_IO_ERROR_FAILED;
- }
+ GIOErrorEnum giocode = _ostree_fetcher_http_status_code_to_io_error (response);
if (req->idx + 1 == req->mirrorlist->len)
{
soup_uri_to_string (soup_request_get_uri (pending->request), FALSE);
GIOErrorEnum code;
+
switch (msg->status_code)
{
- case SOUP_STATUS_NOT_FOUND:
- case SOUP_STATUS_FORBIDDEN:
- case SOUP_STATUS_GONE:
- code = G_IO_ERROR_NOT_FOUND;
- break;
+ /* These statuses are internal to libsoup, and not standard HTTP ones: */
case SOUP_STATUS_CANCELLED:
code = G_IO_ERROR_CANCELLED;
break;
- case SOUP_STATUS_REQUEST_TIMEOUT:
- code = G_IO_ERROR_TIMED_OUT;
- break;
case SOUP_STATUS_CANT_RESOLVE:
case SOUP_STATUS_CANT_CONNECT:
code = G_IO_ERROR_HOST_NOT_FOUND;
#endif
break;
default:
- code = G_IO_ERROR_FAILED;
+ code = _ostree_fetcher_http_status_code_to_io_error (msg->status_code);
+ break;
}
{
return FALSE;
}
+
+/* Convert a HTTP status code representing an error from libsoup or libcurl to
+ * a #GIOError. This will return %G_IO_ERROR_FAILED if the status code is
+ * unknown or otherwise unhandled. */
+GIOError
+_ostree_fetcher_http_status_code_to_io_error (guint status_code)
+{
+ switch (status_code)
+ {
+ case 403: /* SOUP_STATUS_FORBIDDEN */
+ case 404: /* SOUP_STATUS_NOT_FOUND */
+ case 410: /* SOUP_STATUS_GONE */
+ return G_IO_ERROR_NOT_FOUND;
+ case 408: /* SOUP_STATUS_REQUEST_TIMEOUT */
+ return G_IO_ERROR_TIMED_OUT;
+ default:
+ return G_IO_ERROR_FAILED;
+ }
+}
gboolean _ostree_fetcher_should_retry_request (const GError *error,
guint n_retries_remaining);
+GIOError _ostree_fetcher_http_status_code_to_io_error (guint status_code);
+
G_END_DECLS
#endif